package io.renren.modules.generator.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.generator.entity.TestModuleEntity;
import io.renren.modules.generator.entity.TestModuleProjectEntity;
import io.renren.modules.generator.service.TestModuleProjectService;
import io.renren.modules.generator.service.TestModuleService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2021-11-12 13:07:16
 */
@RestController
@RequestMapping("generator/testmodule")
public class TestModuleController {
    @Autowired
    private TestModuleService testModuleService;

    @Autowired
    private TestModuleProjectService testModuleProjectService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:testmodule:list")
    public R list(@RequestParam Map<String, Object> params) {
        // PageUtils page = testModuleService.queryPage(params);

        // List<TestModuleProjectEntity> mpList =
        // testModuleProjectService.selectModuleProjectList();
        // System.out.println("============================");
        // System.out.println("mpList.size() = " + mpList.size());
        // for (TestModuleProjectEntity testModuleProjectEntity : mpList) {
        // System.out.println("------------------------------------------------------------------------------------");
        // System.out.println("testModuleProjectEntity = " +
        // testModuleProjectEntity.getId());
        // System.out.println("getModuleName = " +
        // testModuleProjectEntity.getModuleName());
        // System.out.println("getTester = " + testModuleProjectEntity.getTester());
        // System.out.println("getDeveloper = " +
        // testModuleProjectEntity.getDeveloper());
        // System.out.println("getStatus = " + testModuleProjectEntity.getStatus());
        // System.out.println("getModuleDesc = " +
        // testModuleProjectEntity.getModuleDesc());
        // System.out.println("getProjectId = " +
        // testModuleProjectEntity.getProjectId());
        // System.out.println("getProjectName = " +
        // testModuleProjectEntity.getProjectName());
        // System.out.println("------------------------------------------------------------------------------------");
        // }
        // System.out.println("============================");
        // List<TestModuleProjectEntity> mpListName =
        // testModuleProjectService.queryModuleProjectListByModule("%Blue%");
        // System.out.println("============================");
        // System.out.println("mpList.size() = " + mpListName.size());
        // for (TestModuleProjectEntity testModuleProjectEntity : mpListName) {
        // System.out.println("------------------------------------------------------------------------------------");
        // System.out.println("testModuleProjectEntity = " +
        // testModuleProjectEntity.getId());
        // System.out.println("getModuleName = " +
        // testModuleProjectEntity.getModuleName());
        // System.out.println("getTester = " + testModuleProjectEntity.getTester());
        // System.out.println("getDeveloper = " +
        // testModuleProjectEntity.getDeveloper());
        // System.out.println("getStatus = " + testModuleProjectEntity.getStatus());
        // System.out.println("getModuleDesc = " +
        // testModuleProjectEntity.getModuleDesc());
        // System.out.println("getProjectId = " +
        // testModuleProjectEntity.getProjectId());
        // System.out.println("getProjectName = " +
        // testModuleProjectEntity.getProjectName());
        // System.out.println("------------------------------------------------------------------------------------");
        // }
        // System.out.println("============================");
        PageUtils page = testModuleProjectService.queryModuleProjectPage(params);
        // Page<TestModuleProjectEntity> pageNew = new Page<>(1, 10);
        // testModuleProjectService.listTestModuleProject(pageNew, "Bluetooth");
        // System.out.println("pagesize = " + pageNew.getSize());
        // System.out.println("total count = " + pageNew.getTotal());

        // IPage<TestModuleProjectEntity> iPage = pageNew;

        // IPage<SysUserEntity> page = this.page(new
        // Query<SysUserEntity>().getPage(params),
        // new QueryWrapper<SysUserEntity>().like(StringUtils.isNotBlank(username),
        // "username", username)
        // .eq(createUserId != null, "create_user_id", createUserId));

        // return R.ok().put("page", page);
        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("generator:testmodule:info")
    public R info(@PathVariable("id") Integer id) {
        TestModuleEntity testModule = testModuleService.getById(id);

        return R.ok().put("testModule", testModule);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:testmodule:save")
    public R save(@RequestBody TestModuleEntity testModule) {
        testModuleService.save(testModule);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:testmodule:update")
    public R update(@RequestBody TestModuleEntity testModule) {
        testModuleService.updateById(testModule);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:testmodule:delete")
    public R delete(@RequestBody Integer[] ids) {
        testModuleService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
